package com.goods.controller.business;

import com.github.pagehelper.PageInfo;
import com.goods.business.service.CategoryService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 物资类别
 */
@RequestMapping("/business/productCategory")
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 获取物资类别Tree
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/categoryTree")
    public ResponseBean<PageVO<ProductCategoryTreeNodeVO>> CategoryTree(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize){
        PageVO<ProductCategoryTreeNodeVO> categoryTreeList = categoryService.CategoryTree(pageNum,pageSize);
        return ResponseBean.success(categoryTreeList);
    }

    /**
     * 获取所有父分类
     * @return
     */
    @GetMapping("/getParentCategoryTree")
    public ResponseBean<List<ProductCategoryTreeNodeVO>> getParentCategoryTree(){
        List<ProductCategoryTreeNodeVO> categoryTreeList = categoryService.getParentCategoryTree();
        return ResponseBean.success(categoryTreeList);
    }

    /**
     * 添加分类
     * @param productCategoryVO
     * @return
     */
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductCategoryVO productCategoryVO){
        categoryService.addProductCategory(productCategoryVO);
        return ResponseBean.success();
    }

    /**
     * 根据id回显数据
     * @param id
     * @return
     */
    @GetMapping("edit/{id}")
    public ResponseBean<ProductCategoryVO> edit(@PathVariable Long id){
        ProductCategoryVO productCategoryVO = categoryService.edit(id);
        return ResponseBean.success(productCategoryVO);
    }

    /**
     * 修改分类
     * @param productCategoryVO
     * @return
     */
    @PutMapping("/update/{id}")
    public ResponseBean undefined (@RequestBody ProductCategoryVO productCategoryVO,@PathVariable Long id){
        categoryService.updateProductCategory(productCategoryVO,id);
        return ResponseBean.success();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteById(@PathVariable Long id){
        categoryService.deleteById(id);
        return ResponseBean.success();
    }
}
